#include "board.h"
#include "AHT20.h"
#include "bflb_gpio.h"

int32_t AHT20ReadTempAndHumi[2] = {0};

void setup() {
  Serial.begin(115200);
  int32_t AHT20ReadTempAndHumi[2] = {0};
  board_init();    /* 板卡初始化 */
  if(AHT20_INIT_RES_OK == AHT20_Init())
	{
		/* AHT20初始化成功 */
		Serial.println("AHT20 Init OK\r\n");
	}
  else
	{
		/* AHT20初始化失败 */
		Serial.println("AHT20 Init Err!!!\r\n");
	}
}

void loop() {
  /* 读取 ATH20 传感器状态 */
  while(AHT20_STA_ERR == AHT20_ReadSta())
  {
    /* 重新初始化AHT20 */
    AHT20_Init();           
    bflb_mtimer_delay_ms(30);
  }
  /* 获取温湿度数据 */
  if (AHT20_READ_OK == AHT20_RecTempAndHumiVal(AHT20ReadTempAndHumi))
  {
    /* 获取成功 */
    Serial.print("AHT20 Read Temperature is:");
    Serial.print((float)AHT20ReadTempAndHumi[1]/10);
    Serial.print("  Humidity is:");
    Serial.println((float)AHT20ReadTempAndHumi[0]/10);
  }
  else
  {
    /* 获取失败 */
    Serial.println("Read Err!!!\r\n");
  }
  delay(1000);
}
